//
//  ExhibitionViewController.m
//  HAODE
//
//  Created by LiYinDi on 16/4/8.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "ExhibitionViewController.h"
//
#import "ExhibitionCategoryViewController.h"
#import <JavaScriptCore/JavaScriptCore.h>
#import "ExhibitionObject.h"

//@protocol TestJSObjectProtocol <JSExport>

// @end
@interface ExhibitionViewController ()<UIWebViewDelegate,TestDelegate>

@end

@implementation ExhibitionViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        self.title = @"展厅";
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated
{
    [self setNavigation];
    [self setAutolayout];
   
   
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
//    [_exhibitionWebview setPaginationMode:UIWebPaginationModeTopToBottom];
    [_exhibitionWebview setBackgroundColor:[UIColor clearColor]];
    NSURL *url = [[NSURL alloc]initWithString:@"http://www.try-shopping.com/tryshopping_wx/exhibition_type_list.html?v=1.0.0"];
    [_exhibitionWebview loadRequest:[NSURLRequest requestWithURL:url]];
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//    [self performSelector:@selector(getAchieveWebViewHeight) withObject:nil afterDelay:0.3];
 
    JSContext *context=[webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
    
    //js调用iOS
    //第一种情况
    //其中test1就是js的方法名称，赋给是一个block 里面是iOS代码
    
    ExhibitionObject *exhiObject=[ExhibitionObject  new];
    exhiObject.delegate=self;
    context[@"appJs"]=exhiObject;
   
   
}
-(void)itemClick:(NSString *)url
{
   
//    NSLog(@"url//===%@",url);
    ExhibitionCategoryViewController *vc=[[ExhibitionCategoryViewController alloc] init];
        vc.url=url;
    
    [self.navigationController pushViewController:vc animated:YES  ];
}
-(void)getAchieveWebViewHeight
{
    NSString *meta = [NSString stringWithFormat:@"document.getElementsByName(\"viewport\")[0].content = \"width=%f, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\"", _exhibitionWebview.frame.size.width];
    NSLog(@"_exhibitionWebview.frame.size.width//===%f",_exhibitionWebview.frame.size.width);
    [_exhibitionWebview stringByEvaluatingJavaScriptFromString:meta];
}

-(void)setNavigation
{
    [[self rdv_tabBarController] setTabBarHidden:NO];
    self.navigationController.navigationBarHidden=NO;
     [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    
    
    UILabel *titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0,100, 21)];
    titleLabel.textAlignment=NSTextAlignmentCenter;
    titleLabel.text=@"展厅";
    
    self.navigationItem.titleView = titleLabel;
    
    self.navigationController.navigationBar.barStyle =UIBaselineAdjustmentNone ;
    
     UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    lineLabel.textColor=[UIColor clearColor];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
 
}
-(void)setAutolayout
{
//    [_label mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.equalTo(self.view.mas_bottom);
//        make.left.equalTo(self.view.mas_left);
//        make.right.equalTo(self.view.mas_right);
//        make.top.equalTo(self.view.mas_top).with.offset(100);
//        NSLog(@"WWWWW=========%f",_label.frame.size.width);
//        
//    }];
    [_exhibitionWebview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_bottom);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(self.view.mas_top);
//        NSLog(@"WWWWW=========%f",_exhibitionWebview.frame.size.width);
        
    }];
   
    
}

@end
